package com.ruoyi.web.controller.picture;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.picture.domain.FamParm;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.picture.domain.Fam;
import com.ruoyi.picture.service.IFamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家人账单Controller
 * 
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/picture/fam")
public class FamController extends BaseController
{
    @Autowired
    private IFamService famService;

    /**
     * 查询家人账单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Fam fam)
    {
        startPage();
        List<Fam> list = famService.selectFamList(fam);
        return getDataTable(list);
    }

    @PostMapping("famAdd")
    public AjaxResult famAdd(@RequestBody FamParm famParm)
    {
        return toAjax(famService.insertFams(famParm));
    }


    /**
     * 导出家人账单列表
     */
    @PreAuthorize("@ss.hasPermi('picture:fam:export')")
    @Log(title = "家人账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fam fam)
    {
        List<Fam> list = famService.selectFamList(fam);
        ExcelUtil<Fam> util = new ExcelUtil<Fam>(Fam.class);
        util.exportExcel(response, list, "家人账单数据");
    }

    /**
     * 获取家人账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('picture:fam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(famService.selectFamById(id));
    }

    /**
     * 新增家人账单
     */
    @PreAuthorize("@ss.hasPermi('picture:fam:add')")
    @Log(title = "家人账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fam fam)
    {
        return toAjax(famService.insertFam(fam));
    }



    /**
     * 修改家人账单
     */
    @PreAuthorize("@ss.hasPermi('picture:fam:edit')")
    @Log(title = "家人账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fam fam)
    {
        return toAjax(famService.updateFam(fam));
    }

    /**
     * 删除家人账单
     */
    @PreAuthorize("@ss.hasPermi('picture:fam:remove')")
    @Log(title = "家人账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(famService.deleteFamByIds(ids));
    }
}
